<?php
$debugAdminManageProducts = FALSE;
require("../../../class2.php");
require("../library/admin/adminapi.php");

if(!getperms("P")){header("location:".e_BASE."index.php"); exit; }

if ($debugAdminManageProducts && ADMIN) $ns->tablerender("Debug: All the REQUEST vars", print_a($_REQUEST, TRUE));

// Make data safe
foreach ($_POST as $key => $value) $_POST[$key] = $value;

$countcats = $sql -> db_Select($e107shop_db_name['categories'], "*", "");
if (!$countcats) {
    header("location:admin_manage_categories.php");
}
$e_wysiwyg = "product_description";
require_once(e_ADMIN."auth.php");
isset($_GET['g']) ? $category = (int) $_GET['g'] : $category = 0;
//
// Process the Form
//
if($_POST["subbed"])
{
    $functions = str_replace("(","",$_POST["cur_functions"]);
    $functions = str_replace(")","", $functions);
    $functions = $functions."(".$_POST["go_to_page"].")";
    e107shop_process_product($_POST["faction"], $_POST["productid"], $_POST["large_image"], $_POST["Enabled"], 
    $_POST["product_description"], $_POST["stock_on_hand"], $_POST["product_price"], $_POST["postage_price"], 
    $_POST["product_name"], $_POST["active"], $_POST["download"], $_POST["download_file"], 
    $_POST["special_price"], $_POST["product_tier"], $functions, $_POST["customize"], $_POST["cust_cat"], 
    $_POST["fname_1"], $_POST["fname_2"], $_POST["fname_3"], $_POST["fname_4"], $_POST["fname_5"], 
    $_POST["fname_6"], $_POST["fname_7"], $_POST["fname_8"], $_POST["fname_9"], $_POST["fname_10"], 
    $_POST["fname_11"], $_POST["fname_12"], $_POST["fname_13"], $_POST["fname_14"], $_POST["fname_15"], 
    $_POST["fname_16"], $_POST["fname_17"], $_POST["fname_18"], $_POST["fname_19"], $_POST["fname_20"], 
    $_POST["thumb_only"]);
}

// If there is a delete-action, process it BEFORE loading the rest
if($_GET['a'] == 2) {
    $sql->db_Delete($e107shop_db_name['products'], "ID=".$tp->toDB($_GET['p']));
    $sql->db_Delete($e107shop_db_name['category_matrix'], "product_id=".$tp->toDB($_GET['p']));
    $ns->tablerender("<center>".lan_global_status."</center>", 
    "<center><br />".lan_global_deleted."</center>");
} elseif ($_GET['a'] == 3) {
    $sql->db_Update($e107shop_db_name['products'], "active=2 where ID=".$tp->toDB($_GET['p']));
    $ns->tablerender("<center>".lan_global_status."</center>", 
    "<center><br />".lan_global_updated."</center>");
}

//
// Display the list of products
//
e107shop_display_current_products($category);

//
// Display the form
//
e107shop_manage_product($_GET["a"], $_GET["p"]);

require_once(e_ADMIN."footer.php");
